#ifndef YY_MOBILE_POST_UTIL_INCLUDED
#define YY_MOBILE_POST_UTIL_INCLUDED

#define EPSILON         1.0e-4

//
// Quadratic color thresholding
// curve = (threshold - knee, knee * 2, 0.25 / knee)
//
half4 QuadraticThreshold(half4 color, half threshold, half3 curve)
{
	// Pixel brightness
	//half br = Max3(color.r, color.g, color.b);
	half br1 = max(color.r, color.g);
	half br = max(br1, color.b);

	// Under-threshold part: quadratic curve
	half rq = clamp(br - curve.x, 0.0, curve.y);
	rq = curve.z * rq * rq;

	// Combine and apply the brightness response curve.
	color *= max(rq, br - threshold) / max(br, EPSILON);

	return color;
}

//half4 Combine(half4 bloom, float2 uv)
//{
//	//half4 color = SAMPLE_TEXTURE2D(_BloomTex, sampler_BloomTex, uv);
//	half4 color = tex2D(_BloomTex, uv);
//	return bloom + color;
//}

// 
half4 DownsampleBox4Tap(sampler2D _MainTex,float2 uv, float2 texelSize)
{
	float4 d = texelSize.xyxy * float4(-1.0, -1.0, 1.0, 1.0);
	//half4 s;

	fixed4 result = tex2D(_MainTex, uv + d.xy);
	result += tex2D(_MainTex, uv + d.zy);
	result += tex2D(_MainTex, uv + d.xw);
	result += tex2D(_MainTex, uv + d.zw);

	return result * 0.25h;
}

#endif